// modules/order/order.controller.ts

import { Provide, Inject } from '@midwayjs/core';
import { CoolController, BaseController, BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Column, Entity, PrimaryGeneratedColumn, CreateDateColumn, Repository, ManyToMany, JoinTable } from 'typeorm';

/**
 * 订单表
 */
@Entity('order')
export class OrderEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'varchar', length: 64, unique: true, comment: '订单编号' })
  orderNo: string;

  @Column({ type: 'int', comment: '用户ID' })
  userId: number;

  @Column({ type: 'int', comment: '订单状态，0-待付款，1-已付款，2-已发货，3-已完成，4-已取消' })
  status: number;

  @Column({ type: 'int', comment: '支付状态，0-未支付，1-已支付，2-退款中，3-已退款' })
  paymentStatus: number;

  @Column({ type: 'numeric', precision: 12, scale: 2, default: 0, comment: '总金额' })
  totalAmount: number;

  @Column({ type: 'text', comment: '商品列表（JSON格式）' })
  items: string;

  @Column({ type: 'varchar', length: 512, comment: '收货地址' })
  shippingAddress: string;

  @Column({ type: 'text', nullable: true, comment: '备注' })
  remark: string;

  @CreateDateColumn({ type: 'timestamp', comment: '订单创建时间' })
  createTime: Date;

  @Column({ type: 'timestamp', nullable: true, comment: '支付时间' })
  paymentTime: Date;
}



/**
 * 订单控制器
 */
@Provide()
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: OrderEntity,

})
export class OrderController extends BaseController {


  // 可扩展自定义接口
  // @Post('/custom')
  // async custom(@Body() body) {
  //   return this.ok(await this.orderService.someMethod(body));
  // }
}
